package com.fl.anno3d.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.fl.anno3d.param.MvtParam;
import com.fl.anno3d.param.PropertyParam;
import com.fl.anno3d.param.RecTangleParam;
import com.fl.anno3d.param.ZoomLevelParam;
import com.fl.anno3d.service.ProinceService;
import com.fl.anno3d.util.AjaxResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 18210
 */
@RestController
@RequestMapping("/data")
@Api("测试用接口")
public class DataController {

    @Autowired
    private ProinceService proinceService;

    @ApiOperation("获取mvt数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "table" ,value = "空间表名称",required = true,dataType = "String",example = "province"),
            @ApiImplicitParam(name = "z" ,value = "z",required = true,dataType = "Integer",example = "9"),
            @ApiImplicitParam(name = "x" ,value = "x",required = true,dataType = "Integer",example = "425"),
            @ApiImplicitParam(name = "y" ,value = "y",required = true,dataType = "Integer",example = "218"),
    })
    @ApiResponse(code = 200, message = "操作成功", response = Byte.class)
    @GetMapping("/getMvt/{table}/{z}/{x}/{y}")
    public AjaxResult getMvt(@PathVariable String table, @PathVariable Integer x, @PathVariable Integer y, @PathVariable Integer z){
        MvtParam param = new MvtParam();
        param.setTable(table);
        param.setX(x);
        param.setY(y);
        param.setZ(z);
        return AjaxResult.success(proinceService.getMvtData(param));
    }

    @ApiOperation("获取兴趣点geojson")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "table" ,value = "空间表名称",required = true,dataType = "String",example = "test") ,
            })

    @GetMapping("/getPOIJson/{table}")
    public AjaxResult getPOIJson(@PathVariable String table, RecTangleParam param, ZoomLevelParam param2, PropertyParam param3){
      List<String> result = proinceService.getPOIJson(table,param2,param,param3);
        JSON json = JSONUtil.parse(result);
        return AjaxResult.success(json);
    }

    @GetMapping("/test")
    public AjaxResult test(){
        return AjaxResult.success("欢迎光临！");
    }
}
